<template>
	<layout :loading="loadingData" pageKey="navbar" :title="data._id ? '修改导航':'新增导航'">

		<form @submit="submit" data-action="admin/navbar/save" data-back="/pages/navbar/list" data-clear="admin/navbar/list">

			<view class="w650">
				 <uploads title="导航图" name="x.icon" v-model="data.icon" :count="1"></uploads>	
				<inputs name="x.name|名称" title="名称" :value="data.name"></inputs>
				
				<selects title="上级导航" :list="navlist" name="x.parent_id"
				:value="data.parent_id" titleKey="name" valueKey="_id"></selects>
				
				<inputs name="x.url|菜单url" title="菜单url" :value="data.url"></inputs>
				<inputs name="x.sort|排序" title="排序" type="number" :value="data.sort"></inputs>
			
				<switchs  name="x.isshow|是否显示" title="是否显示" v-model="data.status" ></switchs>

				<labels class="mt40">
					<inputs type="hidden" name="x._id" :value="id" v-if="id"></inputs>
					<button class="btn greenBg w80" form-type="submit">{{ !data._id ? '保存' : '修改'}}</button>
					<button class="btn grayBg line w80" @click="bcc.goBack()">取消</button>
				</labels>
			</view>
		</form>

	</layout>
</template>

<script>
	export default {
		data() {
			return {
				loadingData: true,
				id: '',
				data: {},
				navlist:[]
			}
		},

		onLoad(params) {
			this.id = params.id;
			
			this.getList();
		},

		methods: {
			submit: function(e) {
				this.bcc.submit(e);
			},
			loadData: function(e) {
				var that = this;
				var data = {
					id: this.id
				};
				this.bcc.call({
					url: 'admin/navbar/info',
					data: data,
					success: res => {
						this.data = res.data || {};
						// this.typeList = res.typeList ;
						this.loadingData = false;
					}
				});
			},
			getList:function(e){
				if (!this.loading) {
					uni.showLoading({
						title:"加载中…"
					});
				}
				this.bcc.callInCache({
					url : 'admin/navbar/list',
					success : e => { 
						this.navlist = e.list.filter(e=>e.parent_id=='').map(item=>{							
							return item ;
						}) ;
						this.loadData();
						this.loading = false ;
						uni.hideLoading();
					}
				});
			},


		}
	}
</script>

<style>

</style>
